// Package domain
// Created by GoLand
// @User: lenora
// @Date: 2024/8/16
// @Time: 11:09

package domain

import (
	"github.com/robfig/cron/v3"
	"time"
)

type Job struct {
	Id         uint64
	Executor   string
	Spec       string //cron表达式
	CancelFunc func()
}

// Next 计算下次执行时间
func (j *Job) Next() time.Time {
	parser := cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
	s, _ := parser.Parse(j.Spec)
	return s.Next(time.Now())
}
